package org.dromara.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.dromara.system.domain.bo.SysLabelBo;
import org.dromara.system.domain.vo.SysLabelVo;
import org.dromara.system.domain.SysLabel;
import org.dromara.system.mapper.SysLabelMapper;
import org.dromara.system.service.ISysLabelService;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 系统管理-门店标签配置Service业务层处理
 *
 * @author LionLi
 * @date 2024-03-18
 */
@RequiredArgsConstructor
@Service
public class SysLabelServiceImpl implements ISysLabelService {

    private final SysLabelMapper baseMapper;



    /**
     * 查询系统管理-门店标签配置列表
     */
    @Override
    public List<SysLabelVo> queryList() {
        return  baseMapper.selectVoList();
    }


    /**
     * 新增系统管理-门店标签配置
     */
    @Override
    public Boolean insertByBo(SysLabelBo bo) {
        SysLabel add = MapstructUtils.convert(bo, SysLabel.class);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setLabelId(add.getLabelId());
        }
        return flag;
    }

    /**
     * 修改系统管理-门店标签配置
     */
    @Override
    public Boolean updateByBo(List<SysLabelBo> bos) {
        ArrayList<SysLabel> sysLabels = new ArrayList<>();
        for (SysLabelBo bo : bos) {
            SysLabel update = MapstructUtils.convert(bo, SysLabel.class);
            sysLabels.add(update);

        }
        return baseMapper.updateBatchById(sysLabels);
    }


    /**
     * 批量删除系统管理-门店标签配置
     */
    @Override
    public Boolean deleteWithValidByIds(List<String> ids) {
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    /**
     * 校验门店标签是否唯一
     *
     * @param bo
     * @return
     */
    @Override
    public Boolean checkLabeName(SysLabelBo bo) {
        long labelId = ObjectUtil.isNull(bo.getLabelId()) ? -1L : bo.getLabelId();
        SysLabel sysLabel = baseMapper.selectOne(new LambdaQueryWrapper<SysLabel>().eq(SysLabel::getLabelName, bo.getLabelName()));
        if (ObjectUtil.isNotNull(sysLabel) && sysLabel.getLabelId() != labelId) {
            return false;
        }
        return true;
    }
}
